import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/network/network_connectivity.dart';

//网络连接类型
enum ConnectivityType{
  WiFi,
  MobileNetwork,
  NoInternet,
}
final ConnectivityTypeMessage={
  ConnectivityType.WiFi:'WiFi',
  ConnectivityType.MobileNetwork:'移动网络',
  ConnectivityType.NoInternet:'无网络连接',
};
class NetWorkConnectivityBloc extends Bloc<NetWorkConnectivityEvent,NetWorkConnectivityState>{
  NetworkConnectivity _networkConnectivity;
  NetWorkConnectivityBloc():
        super(NetWorkConnectivityState(connectivityType:ConnectivityType.NoInternet,
        isShow: true,
        isLoading: true ,)){
    _networkConnectivity=NetworkConnectivity(netWorkConnectivityBloc: this);
  }
  Stream<NetWorkConnectivityState> mapEventToState(NetWorkConnectivityEvent event)async*{
    yield NetWorkConnectivityState(connectivityType:event.connectivityType,isShow: true,isLoading: false );
  }
}

class NetWorkConnectivityEvent extends Equatable{
  final bool isShow;//是否显示
  final ConnectivityType connectivityType;
  NetWorkConnectivityEvent({@required this.isShow,@required this.connectivityType});
  @override
  List<Object> get props=>[isShow];
}
class NetWorkConnectivityState extends Equatable{
  final ConnectivityType connectivityType;
  final isShow;//是否显示
  final isLoading;//初始化
  NetWorkConnectivityState({@required this.connectivityType,@required this.isShow,@required this.isLoading});
  List<Object> get props=>[connectivityType,isShow,isLoading];
}